import { createStore } from "vuex";

// 创建一个新的 store 实例

export interface Store {
  currentStep: number;
  steps: Array<{ title: string; footer: string }>;
  selectedTemplate: string;
  templateUrl: string;
  reportData: Record<string, any>;
}
const store = createStore<Store>({
  state() {
    return {
      currentStep: 0,
      steps: [
        { title: "报表选择", footer: "开始填报" },
        { title: "报表填写", footer: "预览" },
        { title: "预览填报", footer: "确认填报" },
      ],
      selectedTemplate: "",
      templateUrl: "https://www.baidu.com",
      reportData: {
        name: "小明",
        age: "18",
        gental: "male",
      },
    };
  },
  mutations: {
    nextStep(state) {
      if (state.currentStep < state.steps.length) {
        state.currentStep++;
      }
    },
    previousStep(state) {
      if (state.currentStep > 0) {
        state.currentStep--;
      }
    },
    selectedTemplate(state, payload: string) {
      state.selectedTemplate = payload;
    },
  },
  getters: {
    getCurrentStepTitle(state) {
      return state.steps[state.currentStep].title;
    },
    getCurrentStepFooter(state) {
      return state.steps[state.currentStep].footer;
    },
  },
});

export default store;
